package com.bussiness.domain;

import java.util.Date;
import java.util.Map;

import org.apache.log4j.Logger;

import com.bussiness.domain.PoiTemplate.Type;


public class PoiFactory {
	private static Logger logger = Logger.getLogger(PoiFactory.class); 
	
	private PoiFactory(){
		super();
	}
	
	public static Poi createPoi(Map <String, String> propValues, PoiTemplate template){
		if (propValues.size()<=0) return null;
		Map<String,Type> propTemplate = template.getProps();
		Poi poi = new Poi();
		poi.setName(template.getName());
		for (String key : propTemplate.keySet()){
			Type t = propTemplate.get(key);
			String value= propValues.get(key);
			if (value!=null){

				switch (t) {
					case Text:{
						poi.addText(key, value);
						break;
					}case Date:{
						long val = Long.parseLong(value);
						Date date = new Date(val);
						poi.addDate(key, date);
						break;
					}case Number:{
						Integer val = Integer.parseInt(propValues.get(value));
						poi.addNumber(key, val);
						break;
					}case Boolean:{
						Boolean val = Boolean.parseBoolean(propValues.get(value));
						poi.addBoolean(key, val);
						break;
					}case Float:{
						Float val = Float.parseFloat(propValues.get(value));
						poi.addFloat(key, val);
						break;
					}case Location:{
						Float lat = Float.parseFloat(propValues.get("lat"));					
						Float lon = Float.parseFloat(propValues.get("lon"));
						Location val = new Location(lat,lon);
						poi.setLocation(val);
						break;
					}case Money:{
						Integer val = Integer.parseInt(propValues.get(value));
						poi.addMoney(key, val);
						break;
					}
/*					case Name:{
						String val = propValues.get(value);
						if (val==null)logger.error("Name is null"); 
						poi.setName(val);
						break;
					}*/	
				}
			}
		}
		logger.info("Poi created: " + poi);
		return poi;		
	}
	
}
